package com.xiyou.luckdraw.web.controller;

import com.xiyou.luckdraw.api.dto.upload.UploadRequest;
import com.xiyou.luckdraw.api.dto.upload.UploadResponse;
import com.xiyou.luckdraw.api.service.IUploadService;
import com.xiyou.luckdraw.common.constants.ResultCodeConstants;
import com.xiyou.luckdraw.common.result.ResponseData;
import com.xiyou.luckdraw.common.result.ResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: UploadController
 * @Description: 图片上传
 * @author: limingxing
 * @Date: 2019-10-10 19:33
 */
@RestController
@RequestMapping("/pic")
@Api(value = "文件上传Controller", tags = {"图片上传接口"})
public class UploadController {

    @Autowired
    private IUploadService uploadService;


    @ApiOperation(value = "上传图片")
    @PostMapping("/upload")
    public ResponseData upload(@RequestParam("file") MultipartFile file) {
        UploadRequest request = new UploadRequest();
        request.setFile(file);
        UploadResponse response = uploadService.upload(request);
        if (response.getCode().equals(ResultCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtils().setData(response);
        }
        return new ResponseUtils().setData(response.getMsg());
    }


}
